package com.david.rocket.controller;

import com.david.rocket.entity.OrderEntity;
import com.david.rocket.service.SpikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SpikeController {
    @Autowired
    private SpikeService spikeService;

    @RequestMapping("/")
    public ResponseEntity<String> index() {
        return ResponseEntity.ok("success");
    }

    @RequestMapping("/go/{goodsId}")
    public ResponseEntity<String> go(@PathVariable String goodsId) {
        String orderId = spikeService.spike(goodsId);
        return ResponseEntity.ok(orderId);
    }

    @RequestMapping("/pay/{orderId}")
    public ResponseEntity<OrderEntity> pay(@PathVariable String orderId) {
        OrderEntity order = spikeService.pay(orderId);
        return ResponseEntity.ok(order);
    }

}
